package my.app.timer;

import android.annotation.SuppressLint;
import android.media.MediaMetadataRetriever;

	public class SongEntry
	{
		public final String songPath;
		public final String songName;
		public String descriptionStr=null;;
		
		@SuppressLint("InlinedApi")
		public SongEntry(String path,String name)
		{
			MediaMetadataRetriever mmr = new MediaMetadataRetriever();
			
			songPath = path;
			songName = name;
			
			//if(new File(path).isDirectory()==false)
			if(songPath!=null)
			{
				mmr.setDataSource(path);
				long durationMs = Long.parseLong(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
	            long duration = durationMs / 1000;
	            long h = duration / 3600;
	            long m = (duration - h * 3600) / 60;
	            long s = duration - (h * 3600 + m * 60);
	            
	            String durationValue;
	            String seconds;
	            
	            if(s <10)
	            	seconds="0"+String.valueOf(s);
	            else
	            	seconds=String.valueOf(s);
	            
	            if(h>=1)
	            	durationValue = String.valueOf(h)+":"+String.valueOf(m)+":"+seconds;
	            else
	            	durationValue = String.valueOf(m)+":"+seconds;
				
				descriptionStr = new String(
						"MP3::"+mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE).subSequence(0, 3)
						+"kbps, "+durationValue+", "
						+mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST));
			}
		}
		
	}
